package com.hl.order.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.hl.order.domain.Printer;
import com.hl.order.service.IPrinterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;

import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 打印机列表Controller
 * 
 * @author ruoyi
 * @date 2025-08-05
 */
@RestController
@RequestMapping("/printer")
public class PrinterController extends BaseController

{
    @Autowired
    private IPrinterService printerService;

    /**
     * 查询打印机列表列表
     */
    @RequiresPermissions("system:printer:list")
    @GetMapping("/list")
    public TableDataInfo list(Printer printer)
    {
        startPage();
        List<Printer> list = printerService.selectPrinterList(printer);
        return getDataTable(list);
    }

    /**
     * 导出打印机列表列表
     */
    @RequiresPermissions("system:printer:export")
    @Log(title = "打印机列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Printer printer)
    {
        List<Printer> list = printerService.selectPrinterList(printer);
        ExcelUtil<Printer> util = new ExcelUtil<Printer>(Printer.class);
        util.exportExcel(response, list, "打印机列表数据");
    }

    /**
     * 获取打印机列表详细信息
     */
    @RequiresPermissions("system:printer:query")
    @GetMapping(value = "/{printerId}")
    public AjaxResult getInfo(@PathVariable("printerId") Long printerId)
    {
        return success(printerService.selectPrinterByPrinterId(printerId));
    }

    /**
     * 新增打印机列表
     */
    @RequiresPermissions("system:printer:add")
    @Log(title = "打印机列表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Printer printer)
    {
        return toAjax(printerService.insertPrinter(printer));
    }

    /**
     * 修改打印机列表
     */
    @RequiresPermissions("system:printer:edit")
    @Log(title = "打印机列表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Printer printer)
    {
        return toAjax(printerService.updatePrinter(printer));
    }

    /**
     * 删除打印机列表
     */
    @RequiresPermissions("system:printer:remove")
    @Log(title = "打印机列表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{printerIds}")
    public AjaxResult remove(@PathVariable Long[] printerIds)
    {
        return toAjax(printerService.deletePrinterByPrinterIds(printerIds));
    }
}
